const { Service } = require("egg");

class UserService extends Service {
    async add(mobile, nickname, email) {
        let sql = "insert into user (mobile, nickname, email) values (?, ?, ?)";
        let params = [mobile, nickname, email];
        let res = await this.app.mysql.query(sql, params);
        return res;
    }

    async findByMobile(mobile) {
        let sql = "select * from user where mobile = ? limit 0, 1";
        let params = [mobile];
        let res = await this.app.mysql.query(sql, params);
        return res[0];
    }

    async getMenuByUid(uid) {
        let sql = `
            select a.path, a.name 
            from acl as a
            join r_role_acl as rra on a.id = rra.aid
            join user as u on rra.rid = u.rid
            where a.type = 1 and u.id = ?
        `;
        let params = [uid];
        let res = await this.app.mysql.query(sql, params);
        return res;
    }
}

module.exports = UserService;
